import {
	configData
} from '@/api/home'

const state = () => ({
	config: {}
});
// 同步
const mutations = {
	//config信息
	SET_CONFIG(state, config) {
		state.config = config;
	},
}
// 异步
const actions = {
	// 获取配置信息
	async getConfig({
		state,
		commit
	}) {
		let config = uni.getStorageSync('config')
		if (config) {
			commit('SET_CONFIG', JSON.parse(config));
			// console.log('旧config', JSON.parse(config));
		} else {
			const {data} = await configData();
			uni.setStorageSync('config', JSON.stringify(data))
			commit('SET_CONFIG', data);
		}
	},
}
export default {
	state,
	mutations,
	actions
};